package com.yhk.wuchat.common.common.exception;

import cn.hutool.http.ContentType;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.yhk.wuchat.common.common.domain.vo.resp.ApiResult;
import com.yhk.wuchat.common.common.util.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.io.Charsets;

import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;
import java.io.IOException;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2024/4/8 15:10
 * @注释
 */
@Getter
@AllArgsConstructor
public enum HttpErrorEnum {
    ACCESS_DENIED(401, "登录失效请重新登录");
    private Integer httpCode;
    private String desc;

    /**
     * 登录异常
     * @param response
     * @throws IOException
     */
    public void sendHttpError(HttpServletResponse response) throws IOException {
        response.setStatus(httpCode);
        response.setContentType(ContentType.JSON.toString(Charsets.UTF_8));
        response.getWriter().write(JsonUtils.toStr(ApiResult.fail(httpCode,desc)));
    }

}
